#include <iostream>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <algorithm>

bool smp_numb(int x) {
    for (int k = 2; k <= static_cast<int>(std::sqrt(x)) + 1; k++) {
        if (x % k == 0) {
            return false;
        }
    }
    return true;
}

std::vector<int> spr() {
    std::vector<int> list_of_nums;
    for (int i = 101; i < 998; i++) {
        if (smp_numb(i)) {
            list_of_nums.push_back(i);
        }
    }
    return list_of_nums;
}

std::unordered_map<std::string, std::string> slov = {
    {"zero", "0"},
    {"one", "1"},
    {"two", "2"},
    {"three", "3"},
    {"four", "4"},
    {"five", "5"},
    {"six", "6"},
    {"seven", "7"},
    {"eight", "8"},
    {"nine", "9"}
};

int main() {
    std::string word;
    std::getline(std::cin, word);

    std::vector<std::string> sl;
    std::string temp = "";
    for (char c : word) {
        if (c == ' ') {
            sl.push_back(temp);
            temp = "";
        } else {
            temp += c;
        }
    }
    sl.push_back(temp);

    std::string h = "";
    for (const auto& m : sl) {
        h += slov[m];
    }

    if (h.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::vector<int> primes = spr();
        int a = *std::max_element(primes.begin(), primes.end(), [&](int x, int y) {
            return std::abs(std::stoi(h) - x) > std::abs(std::stoi(h) - y);
        });
        int b = *std::min_element(primes.begin(), primes.end(), [&](int x, int y) {
            return std::abs(std::stoi(h) - x) < std::abs(std::stoi(h) - y);
        });
        if (std::abs(std::stoi(h) - a) > std::abs(std::stoi(h) - b)) {
            std::cout << b << std::endl;
        } else {
            std::cout << a << std::endl;
        }
    }

    return 0;
}
